// SKNotes - a note taking and gathering tool
// Copyright (C) 2009  Stefan Kueng
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

namespace SKNotes.Configuration
{
    using System;
    using System.Windows.Controls;

	[Serializable]
	internal class GridViewColumnSetting
	{
		public GridViewColumnSetting( GridViewColumn gridViewColumn, int index, int displayIndex )
		{
			if ( gridViewColumn == null )
			{
				throw new ArgumentNullException( "gridViewColumn" );
			}

			this.index = index;
			this.displayIndex = displayIndex;
			this.width = gridViewColumn.Width;
		}

		public int Index
		{
			get { return this.index; }
			set { this.index = value; }
		}

		public int DisplayIndex
		{
			get { return this.displayIndex; }
			set { this.displayIndex = value; }
		}

		public double Width
		{
			get { return this.width; }
			set { this.width = value; }
		}

		public override bool Equals( object obj )
		{
			if ( obj == this )
			{
				return true;
			}

			GridViewColumnSetting compare = obj as GridViewColumnSetting;
			if ( compare == null )
			{
				return false;
			}

			return
				int.Equals( index, compare.index ) &&
				int.Equals( displayIndex,compare.displayIndex ) &&
				double.Equals( width, compare.width );
		}

		public override int GetHashCode()
		{
			int hash = GetType().GetHashCode();
			hash = AddHashCode( hash, index );
			hash = AddHashCode( hash, displayIndex );
			hash = AddHashCode( hash, width );
			return hash;
		} 

		private static int AddHashCode( int hash, object obj )
		{
			int combinedHash = obj != null ? obj.GetHashCode() : 0;
			if ( hash != 0 )
			{
				combinedHash += hash * 31;
			}
			return combinedHash;
		} 

		private int index;
		private int displayIndex;
		private double width;

	}
}
